<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<cl-add-btn />
			<!-- 批量删除按钮 -->
			<cl-multi-delete-btn />
			<cl-flex1 />
			<!-- 关键字搜索 -->
			<cl-search-key />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
import { useCrud, useTable, useUpsert } from '@cool-vue/crud';
import { useCool } from '/@/cool';

defineOptions({ name: 'brand-list' });

const { service } = useCool();

// cl-crud 配置
const Crud = useCrud({ service: service.brand.info }, app => {
	app.refresh();
});

// cl-table 配置
const Table = useTable({
	columns: [
		{ type: 'selection' },
		{ label: '品牌ID', prop: 'brandID', minWidth: 150 },
		{ label: '品牌名称', prop: 'name', minWidth: 140 },
		{
			label: 'Logo',
			prop: 'url',
			minWidth: 100,
			component: { name: 'cl-image', props: { size: 60 } }
		},

		{ label: '创建时间', prop: 'createTime', sortable: 'desc', minWidth: 160 },
		{
			type: 'op',
			buttons: ['edit', 'delete']
		}
	]
});

// cl-upsert 配置
const Upsert = useUpsert({
	items: [
		{ label: '品牌ID', prop: 'brandID', required: true, component: { name: 'el-input' } },
		{ label: '品牌名称', prop: 'name', required: true, component: { name: 'el-input' } },
		{
			label: 'Logo',
			prop: 'url',
			component: { name: 'cl-upload', props: { text: '上传品牌Logo' } }
		}
	]
});
</script>
